package com.jianyi.system.service.log.impl;

import com.jianyi.system.dao.log.SysLogDao;
import com.jianyi.system.model.entity.SysLog;
import com.jianyi.system.service.log.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Optional;

@Service("sysLogService")
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogDao sysLogDao;

    @Override
    public Page<SysLog> findAll(String operation, Pageable pageable) {
        if (StringUtils.isEmpty(operation)){
            return sysLogDao.findAll(pageable);
        }else {
            Page<SysLog> byOperation = sysLogDao.findByOperation(operation, pageable);
            return byOperation;
        }
    }

    @Override
    public Page<SysLog> findByMethod(String method, Pageable pageable) {
        return sysLogDao.findByMethod(method, pageable);
    }

    @Override
    public void save(SysLog sysLog) {
        sysLogDao.save(sysLog);
    }

    @Override
    public Optional<SysLog> get(Long id) {
        return sysLogDao.findById(id);
    }

}
